package com.per.mybootall.test;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2022/1/19
 * Time: 15:40
 * Description:测试  图片缩小，放大
 */
public class test11 {
  public static void main(String[] args) {
    String path="C:\\Users\\admin\\Desktop\\杂货间\\新建文件夹\\huawei.jpg";
zoomImage(path,"C:\\Users\\admin\\Desktop\\杂货间\\新建文件夹\\huawei2.jpg",1400,1400);
  }


  public static void zoomImage(String sourcePath, String destPath, int width, int height) {
    double wr = 0.0D;
    double hr = 0.0D;
    File srcFile = new File(sourcePath);
    File destFile = new File(destPath);

    try {
      BufferedImage bufImg = ImageIO.read(srcFile);
      bufImg.getScaledInstance(width, height, 4);
      wr = (double)width * 1.0D / (double)bufImg.getWidth();
      hr = (double)height * 1.0D / (double)bufImg.getHeight();
      AffineTransformOp ato = new AffineTransformOp(AffineTransform.getScaleInstance(wr, hr), (RenderingHints)null);
      Image itemp = ato.filter(bufImg, (BufferedImage)null);
      ImageIO.write((BufferedImage)itemp, destPath.substring(destPath.lastIndexOf(".") + 1), destFile);
    } catch (Exception var13) {
      var13.printStackTrace();
    }

  }
}
